//
//  UIButton+Block.m
//  runtime
//
//  Created by More on 2017/11/13.
//  Copyright © 2017年 More. All rights reserved.
//

#import "UIButton+Block.h"
#import <objc/runtime.h>

static void *ButtonKey = &ButtonKey;

@implementation UIButton (Block)
//-(void)tapWithEvent:(UIControlEvents)controlEvent withBlock:(TapBlock)tapBlock
//{
//
//    objc_setAssociatedObject(self, ButtonKey, tapBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
//
//    [self addTarget:self action:@selector(btnClick:) forControlEvents:controlEvent];
//}
-(void)tapWithEvent:(UIControlEvents)controlEvent withBlock:(TapBlock)tapBlock
{

    objc_setAssociatedObject(self, ButtonKey, tapBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
    /**
     操你妈
     */
    [self addTarget:self action:@selector(btnClick:) forControlEvents:controlEvent];

}



-(void)btnClick:(UIButton*)sender
{
    
    TapBlock  tapBlock = objc_getAssociatedObject(sender, ButtonKey);
    if (tapBlock) {
        tapBlock(sender);
    }
    
}

    

@end
